package me.monster.lab.androidrforegroundalive

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.Context.NOTIFICATION_SERVICE
import android.util.Log
import androidx.core.content.ContextCompat.getSystemService


/**
 * @description
 * @author: Created jiangjiwei in 2020/10/29 15:12
 */
class NotificationHelper {
    companion object {
        private const val TAG = "NotificationHelper"
        const val notification_channel_id = "Group Id Importance"
        const val notification_channel_name = "Group Name Importance"
    }

    fun init(context: Context) {
        val channel = NotificationChannel(
            notification_channel_id,
            notification_channel_name,
            NotificationManager.IMPORTANCE_HIGH
        )

        val manager = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager?
        manager!!.createNotificationChannel(channel)
    }

    fun checkNotificationChannel(context: Context) {
        val notificationManager = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
        val channels = notificationManager.notificationChannels

        var hasNotification = false
        for (channel in channels) {
            if (channel.id == notification_channel_id) {
                hasNotification = true
                break
            }
        }
        Log.d(TAG, "has notification channel $hasNotification")
        if (!hasNotification) {
            init(context)
        }

    }
}